package com.example.health_life.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface ProductRepository extends JpaRepository<Product,Integer> {

    // 根据标题查询商品(模糊查找)
    @Query("SELECT p FROM Product p WHERE p.title LIKE %:title%")
    List<Product> findByTitle(@Param("title") String title);

    // 根据类型查询商品
    List<Product> findByType(Byte type);

    @Modifying
    @Transactional
    @Query("DELETE FROM Product p WHERE p.id = :id")
    int deleteProductById(@Param("id") Integer id);
}
